package com.zhoutao.blog.seven.model.converter;

import com.zhoutao.blog.seven.dao.model.CommentDao;
import com.zhoutao.blog.seven.model.response.Comment;
import com.zhoutao.blog.seven.utils.TimeUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class CommentConverter extends AbstractConverter<CommentDao, Comment> {


    @Override
    public Comment converterFrom(CommentDao commentDao) {
        Comment comment = new Comment();
        comment.setId(commentDao.getId())
                .setParentId(commentDao.getParentId())
                .setNickname(commentDao.getNickname())
                .setEmail(commentDao.getEmail())
                .setContent(commentDao.getContent())
                .setCreatedAt(TimeUtils.format(commentDao.getCreatedAt()));
        return comment;
    }

    @Override
    public CommentDao converterTO(Comment comment) {
        CommentDao commentDao = new CommentDao();
        commentDao.setId(comment.getId())
                .setParentId(comment.getParentId())
                .setNickname(comment.getNickname())
                .setEmail(comment.getEmail())
                .setContent(comment.getContent())
                .setRefId(comment.getRefId());
        return commentDao;
    }
}
